/*function Shape(){
	this.id 	= id;
	this.vertices = new Array(); //initial relative point position
	this.faces	= [[0,1,2,3],[1,5,6,2],[5,4,7,6],[4,0,3,7],[0,4,5,1],[3,2,6,7]]; // Define the vertices that compose each of the 6 faces. These numbers are indices to the vertex list defined above.
	this.colors = [[255,0,0],[0,255,0],[0,0,255],[255,255,0],[0,255,255],[255,0,255]]; // Define the colors for each face.
	this.points = new Array(); //canvas coordinates for each point
}*/
function Shape(){
	this.id = null;
	this.parent = null;
	this.coordinats = [];
	this.colors = [];
	this.faces  = []; 
	this.initialCenter = [];
	this.polygons = []; 
	this.renderMethod = null;
	this.initialCenter = [];
	
	/* reserved for future */
	this.isDraggable = false;
	this.isRotationCenter = false;
	this.grouped = false;
	
	
}

var CubeModel = function(){
	this.coordinats = [[-1,1,-1],[1,1,-1],[1,-1,-1],[-1,-1,-1],[-1,1,1],[1,1,1],[1,-1,1],[-1,-1,1]];
	this.colors = [
	               [255,0,0],  		//R   
	               [0,255,0],  		//G
	               [0,0,255],  		//B
	               [255,255,0], 	//Yellow
	               [0,255,255], 	//Turquoise
	               [255,0,255]		//Magenta
	               ]; 	
	this.faces  = [[0,1,2,3],[1,5,6,2],[5,4,7,6],[4,0,3,7],[0,4,5,1],[3,2,6,7]];
	
	this.getInstance = function(x,y,z){
		var model = new Shape();
		var tx = 0;
		var ty = 0;
		var tz = 0;
		for(var i=0; i < this.coordinats.length; i++){
			tx = x + this.coordinats[i][0];
			ty = y + this.coordinats[i][1];
			tz = z + this.coordinats[i][2];
			model.coordinats.push([tx,ty,tz]);
			model.colors = this.colors;
			model.faces = this.faces;
		}
		model.initialCenter = [x,y,z];
		model.renderMethod = "fill";
		return model;
	};
};

var cubeFactory = new CubeModel();
var cubes = new Array();
cubes[0] = cubeFactory.getInstance(0,0,0);
cubes[0].colors = [[],[],[],[],[],[]];

cubes[1] = cubeFactory.getInstance(0,0,2);
cubes[1].colors = [[],[],[0,0,255],[],[],[]];

cubes[2] = cubeFactory.getInstance(0,0,-2);
cubes[2].colors = [[255,0,0],[],[],[],[],[]];

cubes[3] = cubeFactory.getInstance(-2,0,0);
cubes[3].colors = [[],[],[],[255,255,0],[],[]]; //cubes[3].renderMethod = "stroke";

cubes[4] = cubeFactory.getInstance(2,0,0);
cubes[4].colors = [[],[0,255,0],[],[],[],[]];

cubes[5] = cubeFactory.getInstance(0,2,0);
cubes[5].colors = [[],[],[],[],[0,255,255],[]];

cubes[6] = cubeFactory.getInstance(0,-2,0);
cubes[6].colors = [[],[],[],[],[],[255,0,255]];

cubes[7] = cubeFactory.getInstance(-2,0,2);
cubes[7].colors = [[],[],[0,0,255],[255,255,0],[],[]];

cubes[8] = cubeFactory.getInstance(2,0,2);
cubes[8].colors = [[],[0,255,0],[0,0,255],[],[],[]];

cubes[9] = cubeFactory.getInstance(-2,0,-2);
cubes[9].colors = [[255,0,0],[],[],[255,255,0],[],[]];

cubes[10] = cubeFactory.getInstance(2,0,-2);
cubes[10].colors = [[255,0,0],[0,255,0],[],[],[],[]];

cubes[11] = cubeFactory.getInstance(-2,-2,2);
cubes[11].colors = [[],[],[0,0,255],[255,255,0],[],[255,0,255]];

cubes[12] = cubeFactory.getInstance(0,-2,2);
cubes[12].colors = [[],[],[0,0,255],[],[],[255,0,255]];

cubes[13] = cubeFactory.getInstance(2,-2,2);
cubes[13].colors = [[],[0,255,0],[0,0,255],[],[],[255,0,255]];

cubes[14] = cubeFactory.getInstance(-2,-2,0);
cubes[14].colors = [[],[],[],[255,255,0],[],[255,0,255]];

cubes[15] = cubeFactory.getInstance(2,-2,0);
cubes[15].colors = [[],[0,255,0],[],[],[],[255,0,255]];

cubes[16] = cubeFactory.getInstance(-2,-2,-2);
cubes[16].colors = [[255,0,0],[],[],[255,255,0],[],[255,0,255]];

cubes[17] = cubeFactory.getInstance(0,-2,-2);
cubes[17].colors = [[255,0,0],[],[],[],[],[255,0,255]];

cubes[18] = cubeFactory.getInstance(2,-2,-2);
cubes[18].colors = [[255,0,0],[0,255,0],[],[],[],[255,0,255]];

cubes[19] = cubeFactory.getInstance(-2,2,2);
cubes[19].colors = [[],[],[0,0,255],[255,255,0],[0,255,255],[]]; ///////////////////

cubes[20] = cubeFactory.getInstance(0,2,2);
cubes[20].colors = [[],[],[0,0,255],[],[0,255,255],[]];

cubes[21] = cubeFactory.getInstance(2,2,2);
cubes[21].colors = [[],[0,255,0],[0,0,255],[],[0,255,255],[]];

cubes[22] = cubeFactory.getInstance(-2,2,0);
cubes[22].colors = [[],[],[],[255,255,0],[0,255,255],[]];

cubes[23] = cubeFactory.getInstance(2,2,0);
cubes[23].colors = [[],[0,255,0],[],[],[0,255,255],[]];

cubes[24] = cubeFactory.getInstance(-2,2,-2);
cubes[24].colors = [[255,0,0],[],[],[255,255,0],[0,255,255],[]];

cubes[25] = cubeFactory.getInstance(0,2,-2);
cubes[25].colors = [[255,0,0],[],[],[],[0,255,255],[]];

cubes[26] = cubeFactory.getInstance(2,2,-2);
cubes[25].colors = [[255,0,0],[0,255,0],[],[],[0,255,255],[]];

var AxesModel = function(){
	this.coordinats = [[-5,0,0],[5,0,0],[0,-5,0],[0,5,0],[0,0,-5],[0,0,5]];
	this.colors = [[0,0,0],[0,0,0],[0,0,0]];
	this.faces  = [[0,1],[2,3],[4,5]];
	
	this.getInstance = function(x,y,z){
		var model = new Shape();
		var tx = 0;
		var ty = 0;
		var tz = 0;
		for(var i=0; i < this.coordinats.length; i++){
			tx = x + this.coordinats[i][0];
			ty = y + this.coordinats[i][1];
			tz = z + this.coordinats[i][2];
			model.coordinats.push([tx,ty,tz]);
			model.colors = this.colors;
			model.faces = this.faces;
		}
		model.initialCenter = [x,y,z];
		model.renderMethod = "stroke";
		return model;
	}
}